var rd = require('rd');
var fs = require('fs');
var path = require('path');
let babel = require("@babel/core");
let plugins = [require.resolve('@babel/plugin-transform-flow-strip-types'),'@babel/plugin-proposal-class-properties'];
let folders = [
    'C:/aprepare/zhufeng_debugger_react_202009/src/react/packages/react',
    'C:/aprepare/zhufeng_debugger_react_202009/src/react/packages/react-dom',
    'C:/aprepare/zhufeng_debugger_react_202009/src/react/packages/legacy-events',
    'C:/aprepare/zhufeng_debugger_react_202009/src/react/packages/scheduler',
    'C:/aprepare/zhufeng_debugger_react_202009/src/react/packages/react-reconciler',
    'C:/aprepare/zhufeng_debugger_react_202009/src/react/packages/shared',
]
folders.forEach(folder=>{
    rd.each(folder, function (file, stat, next) {
        if (stat.isFile() && path.extname(file) === '.js') {
            babel.transformFile(file, {presets:["@babel/preset-react"], plugins,code:true }, function (err, result) {
                fs.writeFile(file,result.code,'utf8',(err)=>{
                    if (err) throw err;
                    next();
                });
            });
        }else{
            next();
        }
    }, function (err) {
        if (err) throw err;
    });
});
